import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:flutter_meiqia/flutter_meiqia.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: HomePage(),
    );
  }
}

class HomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('MeiQia Test'),
      ),
      body: ListView(
        padding: const EdgeInsets.symmetric(horizontal: 12.0),
        children: <Widget>[
          RaisedButton(
            onPressed: () {
              FlutterMeiqia.registerMeiQia(
                'd9548a894d8a3f5c0431e7fd165b8f84',
//                'a71c257c80dfe883d92a64dca323ec20',
                debugModel: true,
                gravity: MeiQiaTitleGravity.GRAVITY_LEFT,
              ).then((result) {
                print(result.toString());
              });
            },
            child: Text('init MeiQia'),
          ),
          RaisedButton(
            onPressed: () {
              FlutterMeiqia.closeMeiQiaService();
            },
            child: Text('close service'),
          ),
          RaisedButton(
            onPressed: () {
              FlutterMeiqia.openMeiQiaService();
            },
            child: Text('open service'),
          ),
          RaisedButton(
            onPressed: () {
              FlutterMeiqia.conversation(
                settings: ConversionSettings(
                  customizedId: '6c4288d0bb51e452370a99ef9c22c2f3',
                  agentToken: '6c4288d0bb51e452370a99ef9c22c2f3',
                  agentGroupToken: 'f11c83d9cde6e2f11b6430206b3a984a',
                  clientInfo: ClientInfo(
                    name: 'Kuky',
                    gender: '男',
                    age: '18',
                    tel: '18268708556',
                    qq: '615297443',
                    weixin: 'yu_kuky',
                    weibo: 'weiboxxx',
                    address: '浙江宁波宁海',
                    email: 'kukyxingshi@163.com',
                    avatar: 'https://s3.cn-north-1.amazonaws.com.cn/pics.meiqia.bucket/1dee88eabfbd7bd4',
                    source: 'unknown source',
                    comment: 'new customer here',
                    tags: ['A', 'B', 'C'],
                    extras: {'career': 'android develeplor'},
                  ),
                  preSendInfo: PreSendInfo(
//                    message: '我是预发送文字消息',
                    message: '',
                    imagePath: '',
                  ),
                ),
              );
            },
            child: Text('conversion'),
          ),
          RaisedButton(
            onPressed: () {
              FlutterMeiqia.leaveMessage();
            },
            child: Text('leave message'),
          ),
          RaisedButton(
            onPressed: () {
              FlutterMeiqia.getNewMeiQiaId().then((id) {
                print('new mq id is: $id');
              });
            },
            child: Text('get new mq id'),
          ),
          RaisedButton(
            onPressed: () {
              FlutterMeiqia.getCurrentAgent().then((result) {
                if (result.data.isNotEmpty) {
                  var info = MeiQiaAgentInfo.fromMap(result.data);
                  print('${info.toString()}');
                } else {
                  print('get null');
                }
              });
            },
            child: Text('get current agent'),
          ),
          RaisedButton(
            onPressed: () {
              FlutterMeiqia.getCurrentClientId().then((id) {
                print('current client id: $id');
              });
            },
            child: Text('get current clientId'),
          ),
          RaisedButton(
            onPressed: () {
              FlutterMeiqia.createMQClient().then((result) {
                print('current client id: $result');
              });
            },
            child: Text('create mq client'),
          ),
        ],
      ),
    );
  }
}
